﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Data;
using RBOSS.Utilities;
using System.Collections;


namespace RBOSS.Business.AdminModule
{
    public class User_sys
    {
     private RBOSSEntities rb=new RBOSSEntities();

     public int UserId; public int RoleId; public string FirstName; public string LastName; public string Email; public string Password; public string PhoneNo; public string City; public string Province; public string Country; public string PostalCode;
     
        public User_sys()
        {}
        public User_sys(int UserId, int RoleId, string FirstName, string LastName, string Email, string Password, string PhoneNo, string City, string Province, string Country, string PostalCode)
     {
         this.UserId= UserId; 
         this.RoleId = RoleId;
         this.FirstName = FirstName;
         this.LastName = LastName;
         this.Email = Email;
         this.Password = Password;
         this.PhoneNo = PhoneNo;
         this.City = City;
         this.Province = Province;
         this.Country = Country; 
         this.PostalCode = PostalCode;
     }
        public Dictionary<string,string> getUsernames()
     {
            Dictionary<string,string> d=new Dictionary<string,string>(); 
         
            var obj = rb.Users.Select(e => new { e.FirstName, e.UserId });
            foreach (var item in obj)
         {
             d.Add(item.UserId.ToString(), item.FirstName);
             
         }

         return d;
     }

        public User_sys getuserdetail(int userid)
        {
            User_sys user = new User_sys();
            var query = rb.Users.Where(e => e.UserId == userid).FirstOrDefault();
            user.UserId = query.UserId;
            user.RoleId = query.RoleId;
            user.FirstName = query.FirstName;
            user.LastName = query.LastName;
            user.Email = query.Email;
            user.Password = query.Password;
            user.PhoneNo = query.PhoneNo;
            user.City = query.City;
            user.Province = query.Province;
            user.Country = query.Country;
            user.PostalCode = query.PostalCode;
            return user;
        }
        public void adduser(User_sys us)
        {
            Data.User usr=new Data.User();
            usr.UserId= UserId; usr.RoleId = RoleId; usr.FirstName = FirstName; usr.LastName = LastName; usr.Email = Email; usr.Password = Password; usr.PhoneNo = PhoneNo; usr.City = City; usr.Province = Province; usr.Country = Country; usr.PostalCode = PostalCode;
            rb.Users.Add(usr);
            rb.SaveChanges();
        }
        public void update(int userId, int roleId, string firstName, string lastName, string email, string phoneNo, string city, string province, string country, string postalCode)
        {
            var usr = (from s in rb.Users
                        where s.UserId ==userId
                        select s).FirstOrDefault();
            //Data.User usr = new Data.User();
            usr.RoleId = roleId; usr.FirstName = firstName; usr.LastName = lastName; usr.Email = email; usr.PhoneNo = phoneNo; usr.City = city; usr.Province = province; usr.Country = country; usr.PostalCode = postalCode;
            rb.SaveChanges();
        }

    }
}
